package juc.vt;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/*jdk21虚拟线程*/
public class VTThread2 {
    public static void main(String[] args) throws Exception {
        Set<String> sets=ConcurrentHashMap.newKeySet();
        ExecutorService executorService = Executors.newVirtualThreadPerTaskExecutor();
        IntStream.range(0,1000000).forEach(i->{
            executorService.submit(()->{
                String string = Thread.currentThread().toString();
                String s = string.split("@")[1];
                sets.add(s);
                return i;
            });
        });
        TimeUnit.SECONDS.sleep(10);
        System.out.println(sets.size());
    }
}